package com.sz.biz.app.web.filter;

import com.sz.common.base.logger.Logger;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * Function: ApiCostLogFilter. <br>
 * Date: 2017年02月14日 10:46 <br>
 * Author: wentao.chang
 */
@WebFilter(filterName = "apiCostLogFilter", urlPatterns = "/api/*",initParams = {})
public class ApiCostLogFilter implements Filter {

    private Logger logger = Logger.getLogger(this.getClass());


    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        String url = req.getMethod() + " " + req.getRequestURI();

        logger.debug("\r\nstart---" + url);
        long start = System.currentTimeMillis();
        chain.doFilter(request, response);
        long end = System.currentTimeMillis();
        
        logger.debug("\r\nend-----" + url +"         耗时："+(end-start)+"ms \r\n\r\n\r\n");
    }

    @Override
    public void destroy() {

    }
}
